﻿<UserControl x:Class="GSF.TimeSeries.Transport.UI.UserControls.SubscriberUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="850"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls;assembly=GSF.TimeSeries.UI.WPF"
             xmlns:tsfBinding="clr-namespace:GSF.TimeSeries.UI.Binding;assembly=GSF.TimeSeries.UI"
             Background="Transparent">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical">
        <Grid HorizontalAlignment="Center" DataContext="{Binding Path=CurrentItem, Mode=TwoWay}" DataContextChanged="DetailView_DataContextChanged">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="0" Orientation="Horizontal">
                <Button Grid.Row="0" Name="ImportSRQButton" Content="Import SRQ..." Margin="10" Width="{StaticResource SmallerItemSize}" HorizontalAlignment="Left" Click="ImportSRQButton_Click" />
                <Button Grid.Row="0" Name="ImportCERButton" Content="Import CER..." Margin="10" Width="{StaticResource SmallerItemSize}" HorizontalAlignment="Left" Click="ImportCERButton_Click" />
            </StackPanel>
            
            <GroupBox Grid.Row="1" Header="Subscriber Info">
                <Grid x:Name="GridDetailView" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5">
                    <Grid.BindingGroup>
                        <BindingGroup Name="input"/>
                    </Grid.BindingGroup>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <!--First Row-->
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Acronym"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Text="{tsfBinding:Column Path=Acronym}" Name="AcronymField" CharacterCasing="Upper"/>
                    <TextBlock Grid.Row="0" Grid.Column="2" Text="Name"/>
                    <TextBox Grid.Row="0" Grid.Column="3" Text="{tsfBinding:Column Path=Name}" Name="NameField"/>

                    <!--Second Row-->
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Valid IP Addresses"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Width="480" Text="{tsfBinding:Column Path=ValidIPAddresses}" Name="ValidIpAddressesField"/>
                    
                    <!--Third Row-->
                    <Label Grid.Row="2" Grid.Column="0" Content="Security mode" />
                    <StackPanel Grid.Row="2" Grid.Column="1" Margin="5" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}, Path=DataContext}">
                        <RadioButton Name="TlsRadioButton" GroupName="SecurityMode" Content="TLS" IsChecked="True" Checked="SecurityModeRadioButton_Checked"/>
                        <RadioButton Name="GatewayRadioButton" GroupName="SecurityMode" Content="Gateway" Checked="SecurityModeRadioButton_Checked"/>
                    </StackPanel>
                    <CheckBox Grid.Row="2" Grid.Column="3" Content="Enable PG Connection" IsChecked="{tsfBinding:Column Path=Enabled}" Name="EnablePGConnectionCheckBox" />

                </Grid>
            </GroupBox>

            <GroupBox Grid.Row="2" Header="TLS" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}, Path=DataContext.TransportLayerSecuritySelected}">
                <StackPanel HorizontalAlignment="Center">
                    <Grid Margin="0,20,0,0" HorizontalAlignment="Center">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <!--First Row-->
                        <Label Grid.Row="0" Grid.Column="0" Content="Remote certificate file name" />
                        <StackPanel Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal">
                            <TextBox Width="{StaticResource XXLargeItemSize}" Text="{Binding Mode=TwoWay, Path=RemoteCertificateFile}"/>
                            <CheckBox Name="SelfSignedCheckBox" Margin="10,0,0,0" Content="Self-signed?" IsChecked="{Binding Mode=TwoWay, Path=RemoteCertificateIsSelfSigned}"/>
                        </StackPanel>

                        <!--Second Row-->
                        <Label Grid.Row="1" Grid.Column="0" Content="Valid Policy Errors" />
                        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Mode=TwoWay, Path=ValidPolicyErrors}"/>
                        <Label Grid.Row="1" Grid.Column="2" Content="Valid Chain Flags" />
                        <TextBox Grid.Row="1" Grid.Column="3" Text="{Binding Mode=TwoWay, Path=ValidChainFlags}"/>
                    </Grid>
                </StackPanel>
            </GroupBox>
        </Grid>

        <uc:DetailViewFooterUserControl DeleteCommand="{Binding DeleteCommand}" ClearCommand="{Binding ClearCommand}" SaveCommand="{Binding SaveCommand}"
                SaveEnabled="{tsfBinding:DataOperation Path=(Validation.HasError)}" Name="FooterControl"/>

        <sdk:DataGrid x:Name="DataGridList" ItemsSource="{Binding CurrentPage}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" Height="Auto" PreviewKeyDown="DataGrid_PreviewKeyDown"
                      Sorting="DataGrid_Sorting" SelectedIndex="{tsfBinding:Column Path=CurrentSelectedIndex}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="Acronym" Width="*" Binding="{tsfBinding:Column Path=Acronym}"/>
                <sdk:DataGridTextColumn Header="Name" Width="*" Binding="{tsfBinding:Column Path=Name}" />
                <sdk:DataGridTextColumn Header="Valid IP Addresses" Width="2*" Binding="{tsfBinding:Column Path=ValidIPAddresses}" />
                <sdk:DataGridTextColumn Header="Remote Certificate" Width="2*" Binding="{tsfBinding:Column Path=RemoteCertificateFile}" />
                <sdk:DataGridTemplateColumn Header="Enabled" Width="*">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{tsfBinding:Column Path=Enabled}" HorizontalAlignment="Center" Click="DataGridEnabledCheckBox_Click" />
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

        <uc:DataPagerUserControl CurrentPageNumber="{Binding CurrentPageNumber}" PageCount="{Binding PageCount}"
                                FirstCommand="{Binding FirstCommand}" PreviousCommand="{Binding PreviousCommand}"
                                NextCommand="{Binding NextCommand}" LastCommand="{Binding LastCommand}" VerticalAlignment="Bottom"/>
    </StackPanel>
</UserControl>
